home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_02
/
smith
/
crc16g.h
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-29
|
946b
|
42 lines
/** CRC16G.C
*
* Adapted from CRC-16F.C, a public domain routine
* in Bob Stout's Snippets file collection.
* Adaptations donated to public domain.
*
* Call initcrctab() to initialize table.
*/
#include "crc16.h"
unsigned short crctab[1 << 8];
static int initialized = 0;
#define P 0x1021 /* CRC polynomial */
unsigned short
updcrc(unsigned short crc, /* prev CRC */
const unsigned char *cp, /* new data */
unsigned int cnt) /* # bytes */
{
while (cnt--)
crc = UPDATE_CRC1(*cp++, crc);
return (crc & CRCMASK);
}
void initcrctab(void) {
unsigned int b, v;
int i;
if (initialized)
return;
for (b = 0; b <= (1 << 8) - 1; ++b) {
for (v = b << (CRCW - 8), i = 8; --i >= 0;)
v = v & 0x8000 ? (v << 1) ^ P : v << 1;
crctab[b] = v;
}
initialized = 1;
}
/* End of File */